package com.changgou.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author BAO
 * @version V1.0
 * @Package com.changgou.entity
 * @date 2020/12/6 20:46
 * @description:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    private boolean flag;
    private Integer code;
    private String message;
    private T data;

    public Result(boolean flag, Integer code, String message) {
        this.flag = flag;
        this.code = code;
        this.message = message;
    }


    public static Result success(String msg,Object data){
        return new Result(true,StatusCode.OK,msg,data);
    }

    public static Result fail(String msg){
        return new Result(false,StatusCode.ERROR,msg,null);
    }

    public static Result fail(Integer code,String msg){
        return new Result(false,code,msg,null);
    }
}
